Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoiding direct BuildConfig usage #6517

Merged
merged 23 commits into from
Aug 2, 2022
Merged

Conversation

ouchadam
Copy link
Contributor

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Moves the AnalyticsConfig to the Config
  • Introduces config based LocationConfig, VoipConfig, CryptoConfig
  • Reintroduces the live location sharing feature flag so that clients can opt out at runtime
  • Moves debug and application id to the injectable BuildMeta

Motivation and context

Fixes #6406

Avoids interacting directly with the BuildConfig outside the application level dagger module, this allows us to extract logic to modules which are relying on the build configuration

Screenshots / GIFs

No UI changes

Tests

  • General app smoke test

Tested devices

  • Physical
  • Emulator
  • OS version(s): 29

@@ -284,7 +264,6 @@ android {
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getGplayVersionSuffix()}"

resValue "bool", "isGplay", "true"
buildConfigField "boolean", "ALLOW_FCM_USE", "true"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALLOW_FCM_USE is not used


@InstallIn(SingletonComponent::class)
@Module
object ConfigurationModule {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a dedicated module to provide the abstractions for Config/BuildConfig

@@ -48,31 +48,32 @@ class NotificationBroadcastReceiver : BroadcastReceiver() {
@Inject lateinit var activeSessionHolder: ActiveSessionHolder
@Inject lateinit var analyticsTracker: AnalyticsTracker
@Inject lateinit var clock: Clock
@Inject lateinit var actionIds: NotificationActionIds
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the notification ids include the application package name which is now injected

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement. My 2 cents

fun providesBuildMeta() = BuildMeta()
fun providesBuildMeta() = BuildMeta(
isDebug = BuildConfig.DEBUG,
sdkInt = Build.VERSION.SDK_INT,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdkInt is a bit out of scope for BuildMeta object (I just see that BuildMeta is not new, was not aware of this class before), since Build.VERSION.SDK_INT have different values at runtime (and not at compile time). We have BuildVersionSdkIntProvider on the SDK, and also AndroidVersionTestOverrider (that looks a bit hacky, I would be happier to have a similar BuildVersionSdkIntProvider) app side, which allow to do some test and overriding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very true, happy to swap out for the BuildVersionSdkIntProvider or a :vector version of the same class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used the existing provider 3bfe25a

data class BuildMeta(
val sdkInt: Int = Build.VERSION.SDK_INT
val isDebug: Boolean,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to propagate isDebug to submodules? I think if we chose the Debug (resp Release) buildType, all the submodules will use the same buildType, and so all BuildConfig.DEBUG will have the same values for all modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use the BuildConfig like you've mentioned, I would lean towards abstracting as it provides an entry point for testing, avoid modules needing to generate a BuildConfig and will still work if we start to use pure kotlin modules.

From a build/architecture perspective, ideally variants would only exist at the Android application module level rather than leaking the concept of an element application into the library modules, this will mainly benefit compilation time of multiple variants as the modules will only need to be compiled once for all variants

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. Thanks!

@@ -81,7 +81,8 @@ class HomeActivityViewModel @AssistedInject constructor(
private val analyticsStore: AnalyticsStore,
private val lightweightSettingsStorage: LightweightSettingsStorage,
private val vectorPreferences: VectorPreferences,
private val analyticsTracker: AnalyticsTracker
private val analyticsTracker: AnalyticsTracker,
private val analyticsConfig: AnalyticsConfig,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

analyticsConfig appear to be unused, at least there is no other change form this file in GH interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's because the previous import has been replaced with an instance property of the same name import im.vector.app.config.analyticsConfig -> private val analyticsConfig: AnalyticsConfig

https://github.com/vector-im/element-android/pull/6517/files#diff-7153f5b6cf4c510293d53c73474e854a3a84e6003c88341472c0808377bf3462R118

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, sure.

val DISMISS_ROOM_NOTIF_ACTION = "${buildMeta.applicationId}.NotificationActions.DISMISS_ROOM_NOTIF_ACTION"
val TAP_TO_VIEW_ACTION = "${buildMeta.applicationId}.NotificationActions.TAP_TO_VIEW_ACTION"
val DIAGNOSTIC_ACTION = "${buildMeta.applicationId}.NotificationActions.DIAGNOSTIC"
val PUSH_ACTION = "${buildMeta.applicationId}.PUSH"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are not const val anymore, I think the naming convention is not followed anymore here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* Util class for creating notifications.
* Note: Cannot inject ColorProvider in the constructor, because it requires an Activity
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always a bit sad to see comment blocks vanish.

Copy link
Contributor Author

@ouchadam ouchadam Jul 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to add back, although I'm not sure this comment block adds much?

  • Note: Cannot inject ColorProvider in the constructor, because it requires an Activity

From what I can tell, this technically this isn't true, ColorProvider has an application context injected (unless I've missed something 🤔 )

  • Util class for creating notifications.

Could be avoided by renaming the file to NotificationFactory or NotificationCreator, which helps give the class clarity in its purpose (utility classes can be see as an anti pattern, although extensions get a free pass... 🙃 )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is old comment I think, you are right. Also I do not understand why this class has @Singleton. And yes this would definitely needs a renaming. This class is maybe 6 or 7 years old :).

)

@Provides
fun providesVoipConfig() = VoipConfig(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 for splitting between several small config classes!

@bmarty
Copy link
Member

bmarty commented Jul 12, 2022

More remarks:

@ouchadam
Copy link
Contributor Author

ouchadam commented Jul 12, 2022

More remarks:

ahh I had only checked the vector module BuildConfig

for the SDK config it depends if we want the values to be available for consumers of the library vs only us/source compilers, at the moment the artifact we release is always DEBUG=false https://github.com/vanniktech/gradle-maven-publish-plugin/blob/master/plugin/src/main/kotlin/com/vanniktech/maven/publish/MavenPublishPlugin.kt#L78

if we want to respect the debug config of the consumer app then the debug flag should be passed as part of the MatrixConfiguration, I would be tempted to make it public static for simplicity 🤔

to help keep this PR smaller I would prefer to make the changes within the SDK as part of a separate PR but will fix the other points you've mentioned 👍

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update. one final remark

is EventSharedAction.OnUrlClicked -> {
onUrlClicked(action.url, action.title)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange to see all those new lines. Is there a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will revert, it looks like the autoformatting is doing something strange

I have the same issue when formatting this file on other branches

@ouchadam ouchadam force-pushed the feature/adm/build-config branch 2 times, most recently from 4c0dd91 to 7ed39ed Compare July 29, 2022 13:21
@sonarcloud
Copy link

sonarcloud bot commented Aug 2, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 3 Security Hotspots
Code Smell A 0 Code Smells

35.5% 35.5% Coverage
0.3% 0.3% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid direct BuildConfig usages
2 participants